package cc.rengu.redp.bizimpl.monitor.controller;

import cc.rengu.redp.bizimpl.monitor.service.ReloadCacheService;
import cc.rengu.redp.bizimpl.upmp.vo.OperationResult;
import cc.rengu.redp.common.exception.RedpException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "运维监控")
@Slf4j
@RestController
@RequestMapping("/admin/reloadCache")
public class ReloadCacheController {


    @Autowired
    private ReloadCacheService reloadCacheService;

    @PostMapping("/edit")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "instId", value = "机构标识", required = true, dataType = "String"),
            @ApiImplicitParam(paramType = "query", name = "cacheType", value = "缓存类型", required = true, dataType = "String")
    })
    public OperationResult editSave(String instId, String cacheType) throws RedpException{
        try {
            return reloadCacheService.reloadCache(instId, cacheType);
        } catch (Exception e) {
            String message = "处理失败";
            log.error(message, e);
            throw new RedpException(message);
        }

    }

}
